package com.ruoyi.project.lesson.transcodetask.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.lesson.transcodetask.domain.TranscodeTask;
import com.ruoyi.project.lesson.transcodetask.service.ITranscodeTaskService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 转码任务Controller
 * 
 * @author shixiangwen
 * @date 2020-12-11
 */
@Controller
@RequestMapping("/lesson/transcodetask")
public class TranscodeTaskController extends BaseController
{
    private String prefix = "lesson/transcodetask";

    @Autowired
    private ITranscodeTaskService transcodeTaskService;

    @RequiresPermissions("lesson:transcodetask:view")
    @GetMapping()
    public String transcodetask()
    {
        return prefix + "/transcodetask";
    }

    /**
     * 查询转码任务列表
     */
    @RequiresPermissions("lesson:transcodetask:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(TranscodeTask transcodeTask)
    {
        startPage();
        List<TranscodeTask> list = transcodeTaskService.selectTranscodeTaskList(transcodeTask);
        return getDataTable(list);
    }

    /**
     * 导出转码任务列表
     */
    @RequiresPermissions("lesson:transcodetask:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(TranscodeTask transcodeTask)
    {
        List<TranscodeTask> list = transcodeTaskService.selectTranscodeTaskList(transcodeTask);
        ExcelUtil<TranscodeTask> util = new ExcelUtil<TranscodeTask>(TranscodeTask.class);
        return util.exportExcel(list, "transcodetask");
    }

    /**
     * 新增转码任务
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存转码任务
     */
    @RequiresPermissions("lesson:transcodetask:add")
    @Log(title = "转码任务", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(TranscodeTask transcodeTask)
    {
        return toAjax(transcodeTaskService.insertTranscodeTask(transcodeTask));
    }

    /**
     * 修改转码任务
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        TranscodeTask transcodeTask = transcodeTaskService.selectTranscodeTaskById(id);
        mmap.put("transcodeTask", transcodeTask);
        return prefix + "/edit";
    }

    /**
     * 修改保存转码任务
     */
    @RequiresPermissions("lesson:transcodetask:edit")
    @Log(title = "转码任务", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(TranscodeTask transcodeTask)
    {
        return toAjax(transcodeTaskService.updateTranscodeTask(transcodeTask));
    }

    /**
     * 删除转码任务
     */
    @RequiresPermissions("lesson:transcodetask:remove")
    @Log(title = "转码任务", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(transcodeTaskService.deleteTranscodeTaskByIds(ids));
    }
}
